package com.mrper.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by admin on 2016/3/15.
 */
public class TimeUtil {

    /**
     * 获取时间描述
     * @param millions 要描述的时间戳
     * @return
     */
    public static String getTimeDescription(long millions){
        Calendar now = Calendar.getInstance();
        now.setTime(new Date());
        int nowYear = now.get(Calendar.YEAR);
        int nowDayInYear = now.get(Calendar.DAY_OF_YEAR);
        Calendar fore = Calendar.getInstance();
        fore.setTimeInMillis(Long.valueOf(millions+"000"));
        int foreDayInYear = fore.get(Calendar.DAY_OF_YEAR);
        int foreYear = fore.get(Calendar.YEAR);
//        int foreMonth = fore.get(Calendar.MONTH) + 1;
//        int foreDay = fore.get(Calendar.DAY_OF_MONTH);
//        int foreHour = fore.get(Calendar.HOUR_OF_DAY);
//        int foreMinute = fore.get(Calendar.MINUTE);
        if(nowYear == foreYear){
            String description = "";
            switch(nowDayInYear - foreDayInYear){
                case 0:
                    description = "今日";
                    break;
                case 1:
                    description = "昨天";
                    break;
                case 2:
                    description = "前天";
                    break;
                default:
                    return new SimpleDateFormat("MM-dd HH:mm").format(fore.getTime());
            }
            return description + new SimpleDateFormat("HH:mm").format(fore.getTime());
        }
        return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(fore.getTime());
    }

}
